package cn.edu.lingnan.translation.controller;


import cn.edu.lingnan.translation.entity.Admin;
import cn.edu.lingnan.translation.entity.AdminRole;
import cn.edu.lingnan.translation.service.AdminRoleService;
import cn.edu.lingnan.translation.utils.R;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Bao
 * @since 2020-10-18
 */
@RestController
@RequestMapping("/admin-role")
public class AdminRoleController {
    @Autowired
    private AdminRoleService adminRoleService;

    /**
     * @Description 获取管理员权限信息
     * @Param []
     * @Return cn.edu.lingnan.translation.utils.R
     * @Author BAO
     * @Date 2020/10/18 16:54
     */
    @ApiOperation(value = "获取管理员权限信息")
    @GetMapping("/getAdminRole")
    public R getAdminRole() {
        List<AdminRole> adminRoleList = adminRoleService.list(null);
        return R.ok().data("adminRoleList", adminRoleList);
    }

    /**
     * @Description 删除该管理员的角色
     * @Param [id]
     * @Return cn.edu.lingnan.translation.utils.R
     * @Author BAO
     * @Date 2020/10/18 17:17
     */
    @ApiOperation(value = "删除该管理员的角色")
    @DeleteMapping("/{id}")
    public R deleteAdminRole(@PathVariable String id) {
        adminRoleService.removeById(id);
        return R.ok();
    }

    /**
     * @Description 为用户添加角色
     * @Param [adminRole]
     * @Return cn.edu.lingnan.translation.utils.R
     * @Author BAO
     * @Date 2020/10/18 17:18
     */
    @ApiOperation(value = "为用户添加角色")
    @PostMapping("/add")
    public R addAdminRole(@RequestBody AdminRole adminRole) {
        adminRoleService.save(adminRole);
        return R.ok();
    }
}

